package framework

import (
	"mortnon-go/app/config"
	"net/http"
	"sync"
)

type ApplicationContext struct {
	Routers []func()       // 路由信息
	config  *config.Config // 配置信息
	engine  http.Handler   // 引擎
	mux     sync.RWMutex
	Env     config.Environment // 当前环境
}

var Context *ApplicationContext

// 包导入的时，初始化Context
func init() {
	Context = &ApplicationContext{}
}

func (a *ApplicationContext) SetEngine(engine http.Handler) {
	a.engine = engine
}

func (a *ApplicationContext) GetEngine() http.Handler {
	return a.engine
}

func (a *ApplicationContext) GetEnvironment() config.Environment {
	return a.Env
}

func (a *ApplicationContext) SetEnvironment(env config.Environment) {
	a.Env = env
}

func (a *ApplicationContext) SetConfig(config *config.Config) {
	a.mux.Lock()
	defer a.mux.Unlock()
	a.config = config
}

func (a *ApplicationContext) GetConfig() *config.Config {
	a.mux.Lock()
	defer a.mux.Unlock()
	return a.config
}
